package com.sankuai.inf.leaf.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Configuration
public class PropertyFactory {
    private static final Logger logger = LoggerFactory.getLogger(PropertyFactory.class);
    private static final Properties prop = new Properties();
    @Value("${env}")
    private String env;

//    static {
//        try {
//            prop.load(PropertyFactory.class.getClassLoader().getResourceAsStream("leaf-"+env+".properties"));
//        } catch (IOException e) {
//            logger.warn("Load Properties Ex", e);
//        }
//    }
    @PostConstruct
    public void init(){
        try {
            if (env==null||env.trim().equals("")){
                env="dev";
            }
            prop.load(PropertyFactory.class.getClassLoader().getResourceAsStream("leaf-"+env+".properties"));
        } catch (IOException e) {
            logger.warn("Load Properties Ex", e);
        }
    }
    public static Properties getProperties() {
        return prop;
    }
}
